package su.mvc.service.gui;


import com.googlecode.objectify.Key;
import org.apache.commons.lang.StringUtils;
import su.mvc.model.MenuItem;
import su.mvc.model.PageContent;
import su.mvc.service.DaoSupport;
import su.mvc.service.UserService;

import java.util.logging.Logger;

public class GuiService  extends DaoSupport{

    private static final Logger log = Logger.getLogger(GuiService.class.getName());



    public static final String BY_KEY = "by-key";

    UserService userService;

    MenuService menuService;

    public UserService getUserService() {
        return userService;
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    public MenuService getMenuService() {
        return menuService;
    }

    public void setMenuService(MenuService menuService) {
        this.menuService = menuService;
    }
    
    public MenuItem getContentByIdOrKey(Key key, String id) {
        MenuItem menuItem;
        if (!StringUtils.isEmpty(id) && !BY_KEY.equals(id)) {
            menuItem = getObjectify().query(MenuItem.class).filter("urlString", id).get();
        } else {
            menuItem = (MenuItem)getObjectify().get(key);
        }
        PageContent pageContent = (PageContent)getObjectify().get(new Key(PageContent.class, menuItem.getContentId())); //TODO
        menuItem.setContent(pageContent.getContent());
        return menuItem;
    }
}
